home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-24 | 3.1 KB | 157 lines | [TEXT/PJMM] |
- program FMenus;
-
- { Copyright 1992 Peter N Lewis }
- { This source may be used freely for any purposes. }
- { If you can make any money off this file, you're welcome to it! }
-
- uses
- MyTypes, MyFMenus, BaseGlobals;
-
- const
- hstr = 'FMenus Example Help…'; { Should be in a STR# obviously }
- M_Font = 131;
-
- procedure SetEditMenus (themenu, theitem: integer);
- begin
- writeln('SetEditMenus ', themenu : 1, ':', theitem : 1);
- end;
-
- procedure DoQuit;
- begin
- writeln('Quit');
- quitNow := true;
- end;
-
- procedure DoNew;
- begin
- writeln('New');
- end;
-
- procedure DoAbout;
- begin
- writeln('About');
- end;
-
- procedure SetNewMenu (themenu, theitem: integer);
- begin
- writeln('SetNewMenu ', themenu : 1, ':', theitem : 1);
- EnableItem(GetMHandle(themenu), theitem);
- end;
-
- procedure DefaultMenuProc (themenu, theitem: integer);
- var
- save: grafPtr;
- DAName: str255;
- oe: OSErr;
- begin
- if themenu = M_Apple then begin
- GetPort(save);
- GetItem(GetMHandle(M_apple), theitem, DAName);
- {oe := OpenDeskAcc(DAName);}
- writeln('OpenDeskAcc ', DAName);
- SetPort(save);
- end
- else if themenu = M_Edit then begin
- writeln('Edit: ', theitem : 1);
- end
- else if themenu = M_Font then begin
- writeln('Font: ', theitem : 1);
- end
- else
- writeln('Default Menu Proc ', themenu : 1, ':', theitem : 1);
- end;
-
- procedure Init;
- var
- oe: OSErr;
- gv: longInt;
- mh: MenuHandle;
- begin
- quitNow := false;
-
- InitFMenus(@DefaultMenuProc);
- mh := GetFMenu(M_Apple);
- AddResMenu(mh, 'DRVR');
- InsertMenu(mh, 0);
- mh := GetFMenu(M_File);
- InsertMenu(mh, 0);
- mh := GetFMenu(M_Edit);
- InsertMenu(mh, 0);
- mh := GetFMenu(M_Font);
- AddResMenu(mh, 'FONT');
- InsertMenu(mh, 0);
-
- SetFCommand(Cquit, @DoQuit);
- SetFCommand(Cnew, @DoNew);
- SetFCommand(Cabout, @DoAbout);
- SetFSetMenu(Cundo, @SetEditMenus);
- SetFSetMenu(Ccut, @SetEditMenus);
- SetFSetMenu(Ccopy, @SetEditMenus);
- SetFSetMenu(Cpaste, @SetEditMenus);
- SetFSetMenu(Cclear, @SetEditMenus);
- SetFSetMenu(Cselectall, @SetEditMenus);
- SetFMenus;
- DrawMenuBar;
-
- InitCursor;
- end;
-
- procedure Finish;
- begin
- FinishFMenus;
- end;
-
- procedure EventLoop;
- var
- dummy: boolean;
- er: eventRecord;
- code: integer;
- wp: windowPtr;
- ch: char;
- mResult: longInt;
- begin
- while not quitNow do begin
- dummy := WaitNextEvent(everyEvent, er, 60, nil);
- case er.what of
- mouseDown: begin
- code := FindWindow(er.where, wp);
- if wp = nil then begin
- case code of
- inMenuBar: begin
- SetFMenus;
- mResult := MenuSelect(er.where);
- if mResult <> 0 then begin
- DoFMenu(HiWord(mResult), LoWord(mResult));
- end;
- end;
- otherwise
- end;
- end;
- end;
-
- KeyDown: begin
- ch := chr(BAND(er.message, CharCodeMask));
- mResult := 0;
- if BAND(er.modifiers, CmdKey) <> 0 then begin
- SetFMenus;
- mResult := MenuKey(ch);
- end;
- if mResult <> 0 then
- DoFMenu(HiWord(mResult), LoWord(mResult))
- else
- writeln('Key: ', ch, ' [', er.modifiers : 1, ']');
- end;
- otherwise
- ;
- end;
- end;
- end;
-
- begin
- Init;
-
- ShowText;
- EventLoop;
-
- Finish;
- end.